<?php
declare (strict_types = 1);

namespace app\model;

use think\Model;

class Challenge extends Model
{
    // 设置表名
    protected $name = 'challenges';
    // 定义自动时间戳字段
    protected $autoWriteTimestamp = true;
    protected $createTime = 'created_at';
    protected $updateTime = 'updated_at';

    // 关联发起用户
    public function user()
    {
        return $this->belongsTo(User::class, 'user_id');
    }

    // 关联挑战成员
    public function members()
    {
        return $this->hasMany(ChallengeMember::class, 'challenge_id');
    }
}
